package com.lekang.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.system.domain.NursingHome;
import com.lekang.system.service.INursingHomeService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 养老院Controller
 * 
 * @author zhihao
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/system/home")
public class NursingHomeController extends BaseController
{
    @Autowired
    private INursingHomeService nursingHomeService;

    /**
     * 查询养老院列表
     */
    @PreAuthorize("@ss.hasPermi('system:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(NursingHome nursingHome)
    {
        startPage();
        List<NursingHome> list = nursingHomeService.selectNursingHomeList(nursingHome);
        return getDataTable(list);
    }

    /**
     * 导出养老院列表
     */
    @PreAuthorize("@ss.hasPermi('system:home:export')")
    @Log(title = "养老院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingHome nursingHome)
    {
        List<NursingHome> list = nursingHomeService.selectNursingHomeList(nursingHome);
        ExcelUtil<NursingHome> util = new ExcelUtil<NursingHome>(NursingHome.class);
        util.exportExcel(response, list, "养老院数据");
    }

    /**
     * 获取养老院详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nursingHomeService.selectNursingHomeById(id));
    }

    /**
     * 新增养老院
     */
    @PreAuthorize("@ss.hasPermi('system:home:add')")
    @Log(title = "养老院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingHome nursingHome)
    {
        return toAjax(nursingHomeService.insertNursingHome(nursingHome));
    }

    /**
     * 修改养老院
     */
    @PreAuthorize("@ss.hasPermi('system:home:edit')")
    @Log(title = "养老院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingHome nursingHome)
    {
        return toAjax(nursingHomeService.updateNursingHome(nursingHome));
    }

    /**
     * 删除养老院
     */
    @PreAuthorize("@ss.hasPermi('system:home:remove')")
    @Log(title = "养老院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nursingHomeService.deleteNursingHomeByIds(ids));
    }
}
